package com.briup.app06.web.controller;

import com.briup.app06.bean.Account;
import com.briup.app06.service.IAccountService;
import com.briup.app06.utils.Message;
import com.briup.app06.utils.MessageUtil;
import com.sun.istack.internal.NotNull;
import com.sun.xml.internal.bind.v2.schemagen.XmlSchemaGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/account")
public class AccountController {

    @Resource
    private IAccountService accountService;

    @GetMapping("findAll")
    public Message findAll(){
        List<Account> list = accountService.findAll();
        return MessageUtil.success(list);
    }

    @GetMapping("findById")
    public Message findById(long id){
        Account account = accountService.findById(id);
        return MessageUtil.success(account);
    }

    @PostMapping("save")
    public Message save(@NotNull String account ,@NotNull String password){
        Account a =new Account();
        a.setAccount (account);
        a.setPassword(password);

        accountService.save(a);
        return MessageUtil.success( "保存成功");
    }

    @DeleteMapping("deleteById")
    public Message deleteById(long id) {
        accountService.deleteById(id);
        return MessageUtil.success( "删除成功");
    }
}